package cn.com.self.apis.controller;


import cn.com.self.apis.portal.entity.ClassificationEntity;
import cn.com.self.apis.portal.entity.RequirementsEntity;
import cn.com.self.apis.portal.mapper.ClassificationMapper;
import cn.com.self.apis.portal.mapper.RequirementsMapper;
import cn.com.self.apis.portal.service.intf.IClassificationService;
import cn.com.self.apis.portal.service.intf.IRequirementsService;
import cn.com.self.apis.portal.util.CustomPage;
import cn.com.self.apis.portal.util.ICustomPage;
import cn.com.selfsoft.smartcity.commons.http.ResultModel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author1 ssh
 * @author2
 * @date 2021-04-28
 */
@Controller
@Api(tags = "个人中心-我的需求")
public class PersonalMyRequirementController {

    @Autowired
    RequirementsMapper requirementsMapper;
    @Autowired
    IRequirementsService requirementsService;
    @Autowired
    IClassificationService classificationService;
    @Autowired
    ClassificationMapper classificationMapper;

    @GetMapping(value = {"/my/dispute/id/{memberId}"})
    @ApiOperation(value = "根据用户id获取需求")
    public ResponseEntity getRequirementsByRequirementsId(@PathVariable("memberId") String memberId, Pageable page) {
        Map<String, Object> map = new HashMap(1);
        map.put("member_id", memberId);
//        IPage<RequirementsEntity> requirementsEntityPage = requirementsService.page(map, page);
        CustomPage<RequirementsEntity> requirementsEntityPage = (CustomPage<RequirementsEntity>) requirementsService.page(map, page);
        return ResponseEntity.status(HttpStatus.OK).body(new cn.com.self.apis.core.vo.ResultModel<>(requirementsEntityPage));
    }

    @PostMapping(value = "/classification/page")
    @ApiOperation(value = "分页获取行业分类")
    public ResponseEntity getUserPage(HttpServletRequest request, Pageable page) {
        ICustomPage<ClassificationEntity> iPage = new CustomPage<>(page.getPageNumber(), page.getPageSize());
        QueryWrapper<ClassificationEntity> wrapper = new QueryWrapper<>();
        ICustomPage<ClassificationEntity> backlogEntityIPage = (ICustomPage<ClassificationEntity>) classificationMapper.selectPage(iPage, wrapper);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(backlogEntityIPage));
    }

}

